/**
 * @param {number[][]} obstacleGrid
 * @return {number}
 */
 var uniquePathsWithObstacles = function(obstacleGrid) {  // 动态规划
    if(obstacleGrid[0][0]==1){
        return 0;
    }
    let row=obstacleGrid.length,col=obstacleGrid[0].length;
    for(let i=0;i<row;i++){
        for(let j=0;j<col;j++){
            if(i==0 && j==0){
                obstacleGrid[i][j]=1;
            }
            else if(obstacleGrid[i][j]==1){
                obstacleGrid[i][j]=0;
            }
            else if(i==0){
                obstacleGrid[i][j]=obstacleGrid[i][j-1];
            }
            else if(j==0){
                obstacleGrid[i][j]=obstacleGrid[i-1][j];
            }
            else{
                obstacleGrid[i][j]=obstacleGrid[i-1][j]+obstacleGrid[i][j-1];
            }
        }
    }
    return obstacleGrid[row-1][col-1];
};
var uniquePathsWithObstacles = function(obstacleGrid) {  // 动态规划改，使用一维数组解决
    if(obstacleGrid[0][0]==1){
        return 0;
    }
    let row=obstacleGrid.length,col=obstacleGrid[0].length;
    let f=new Array(col).fill(0);
    f[0]=1;
    for (let i = 0; i < row; i++) {
        for (let j = 0; j < col; j++) {
            if (obstacleGrid[i][j] == 1) {
                f[j] = 0;
                continue;
            }
            if (j - 1 >= 0 && obstacleGrid[i][j - 1] == 0) {
                f[j] += f[j - 1];
            }
            console.log(f);
        }
    }
    console.log(f);
    return f[col-1];
};
console.log(uniquePathsWithObstacles([[0,0,0],[0,1,0],[0,0,0]]))